<template>
	<view>
		<view class="content">
			<u-navbar :fixed="false" title="生产停工" :autoBack="true" :safeAreaInsetTop="true" leftIconColor="#fff">
			</u-navbar>


			<view class="content_main" :style="{ opacity: BtnShow ? 1 : 0, }">
				<m-drag-button :style="{ opacity: BtnShow ? 1 : 0, }" v-show="!formData.Approve" :isDock="true"
					:existTabBar="true" :initialBottom="80" @btnClick="OpenScanBtn">
					<template #BtnContent>
						<u-icon name="scan" color="#fff" size="54rpx"></u-icon>
					</template>
				</m-drag-button>



				<u--form labelPosition="left" :model="formData" :rules="rules" ref="uForm" labelWidth="100px"
					:labelStyle="{'font-size':'14px'}">

					<u-form-item v-if="isEdit" label="单据日期" disabled borderBottom labelWidth="100px"
						:leftIconStyle="{'font-size':'20px'}">
						<u--input v-model="formData.BillDate" readonly placeholder="自动生成" border="none"></u--input>
					</u-form-item>

					<u-form-item v-if="isEdit" label="单据编号" disabled borderBottom labelWidth="100px"
						:leftIconStyle="{'font-size':'20px'}">
						<u--input v-model="formData.BillNO" readonly placeholder="自动生成" border="none"></u--input>
					</u-form-item>

					<u-form-item label="停工日期" borderBottom labelWidth="100px" @click="openBaseScreen('停工日期','picker')"
						:leftIconStyle="{'font-size':'20px'}" prop="ProductionStopSingleDate">
						<view>
							<text>{{$utils.dateFormat(formData.ProductionStopSingleDate,'Y-MM-dd hh:mm:ss')}}</text>
						</view>

						<view slot="right" class="x-f">
							<u-icon name="calendar" size="20" color="#999"></u-icon>
						</view>
					</u-form-item>

					<u-form-item label="派工单编号" borderBottom labelWidth="100px" @click="openBaseScreen('派工单编号','radio')"
						:leftIconStyle="{'font-size':'20px'}" required prop="PGDBillNO">
						<u--input v-model="formData.PGDBillNO" placeholder="请选择/扫描派工单" readonly
							border="none"></u--input>

						<view slot="right" class="x-f">
							<u-icon name="arrow-right" size="20" color="#999"></u-icon>
						</view>
					</u-form-item>

					<u-form-item label="工单编号" borderBottom labelWidth="100px" :leftIconStyle="{'font-size':'20px'}"
						required prop="GDBillNO">
						<u--input v-model="formData.GDBillNO" readonly placeholder="请选择/扫描派工单" border="none"></u--input>
					</u-form-item>

					<u-form-item label="产品信息" disabled borderBottom labelWidth="100px"
						:leftIconStyle="{'font-size':'20px'}">
						<u--input v-model="formData.ProductName" readonly placeholder="选择/扫描派工单后带出"
							border="none"></u--input>
					</u-form-item>

					<u-form-item label="计量单位" disabled borderBottom labelWidth="100px"
						:leftIconStyle="{'font-size':'20px'}">
						<u--input v-model="formData.UnitName" readonly placeholder="选择/扫描派工单后带出"
							border="none"></u--input>
					</u-form-item>

					<u-form-item label="操作人" borderBottom labelWidth="100px" @click="openBaseScreen('操作人','radio')"
						:leftIconStyle="{'font-size':'20px'}" required prop="EmplName">
						<u--input v-model="formData.EmplName" placeholder="请选择操作人" disabled border="none"></u--input>

						<view slot="right" class="x-f">
							<u-icon name="arrow-right" size="20" color="#999"></u-icon>
						</view>
					</u-form-item>

					<u-form-item label="工序" borderBottom labelWidth="100px" @click="openBaseScreen('工序','radio')"
						:leftIconStyle="{'font-size':'20px'}" required prop="ProcedureName">
						<u--input v-model="formData.ProcedureName" placeholder="请选择工序" readonly
							border="none"></u--input>

						<view slot="right" class="x-f">
							<u-icon name="arrow-right" size="20" color="#999"></u-icon>
						</view>
					</u-form-item>

					<u-form-item label="生产车间" disabled borderBottom labelWidth="100px"
						:leftIconStyle="{'font-size':'20px'}">
						<u--input v-model="formData.FWorkshopName" readonly placeholder="选择工序后带出"
							border="none"></u--input>
					</u-form-item>

					<u-form-item label="设备" borderBottom labelWidth="100px" @click="openBaseScreen('设备','radio')"
						:leftIconStyle="{'font-size':'20px'}" prop="EquipmentName">
						<u--input v-model="formData.EquipmentName" placeholder="请选择设备" readonly
							border="none"></u--input>

						<view slot="right" class="x-f">
							<u-icon name="arrow-right" size="20" color="#999"></u-icon>
						</view>
					</u-form-item>

					<u-form-item label="上模模具" borderBottom labelWidth="100px" :leftIconStyle="{'font-size':'20px'}"
						prop="Old_MoludName">
						<u--input v-model="formData.Old_MoludName" disabled placeholder="选择设备后带出"
							border="none"></u--input>
					</u-form-item>

					<u-form-item label="开工单号" borderBottom labelWidth="100px" :leftIconStyle="{'font-size':'20px'}"
						prop="KGBillNO">
						<u--input v-model="formData.KGBillNO" disabled placeholder="选择设备后带出" border="none"></u--input>
					</u-form-item>

					<u-form-item label="备注" leftIcon="attach" :leftIconStyle="{'font-size':'20px'}" class="TopOption">
						<view class="" style="padding: 10px 20px 0;width: 100%;">
							<u--textarea v-model="formData.Comment" placeholder="请输入备注" count
								maxlength="150"></u--textarea>
						</view>
					</u-form-item>

				</u--form>

			</view>



			<view class="BottomBox safe_buttom" :style="$utils.disposeSafeBottomFun()">


				<u-button v-if="!isEdit && ApproveBack('停工提交')" class="content_bottom_primary_Btn" color="#51d0d0"
					style="width: 90%;margin: 0 auto !important;" throttleTime="2000" @click="insetRow"
					text="停工提交"></u-button>

				<view class="x-ec">
					<u-button v-if="isEdit && ApproveBack('继续停工')" class="content_bottom_primary_plainBtn CommonBtnSize"
						style="margin-right: 6px !important;" throttleTime="1000" @click="nextRow"
						text="继续停工"></u-button>

					<u-button v-if="isEdit && ApproveBack('删除')" class="CommonBtnSize" type="error"
						style="margin-right: 6px !important;" throttleTime="1000" @click="deleteRow"
						text="删除"></u-button>

					<u-button v-if="isEdit && ApproveBack('提交')" class="content_bottom_primary_Btn CommonBtnSize"
						color="#51d0d0" style="margin-right: 6px !important;" throttleTime="1000" @click="saveRow"
						text="提交"></u-button>
				</view>
			</view>

		</view>


		<!-- 时间选择器 -->
		<u-datetime-picker class="DateTimerPick" ref="datetimePicker" title="停工日期" :show="showTimePicker"
			v-model="DatetimeData" mode="datetime" :closeOnClickOverlay="true" @close="ClosePicker"
			@cancel="ClosePicker" @confirm="ConfirmTime" :formatter="formatter"></u-datetime-picker>

		<!-- PDA扫码 -->
		<m-pda-scancode v-if="$utils.isPda()" listenName="ProductionStopDetail_Scan"
			:SetContent="{action:$store.state.systemConfig.sysDeviceInfo.broadcastAction,extra:$store.state.systemConfig.sysDeviceInfo.broadcastResult}"></m-pda-scancode>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				showTimePicker: false, // 时间弹层
				DatetimeData: '',
				isEdit: false, // 是否为编辑状态
				BtnShow: false,
				formData: {
					ProductionStopSingleID: 0, // 停工主键ID
					ProductionStopSingleDate: '', // 停工日期 
					BillDate: '',

					JobOrderID: 0,
					PGDBillNO: '',
					WoOrderID: 0,
					GDBillNO: '',
					ProductID: 0,
					ProductName: '',
					UnitID: 0,
					UnitName: '',

					ProcedureID: 0,
					ProcedureName: '', // 工序
					FWorkshopID: 0,
					FWorkshopName: '', // 工作中心
					JobPROCID: 0,
					WoPROCID: 0,

					EmplID: '',
					EmplName: '',
					EquipmentID: 0,
					EquipmentName: '', // 设备
					Old_MoludID: '',
					Old_MoludName: '',
					StartSingleID: 0,
					KGBillNO: '',

					Comment: '',

				},
				rules: {
					'GDBillNO': { // 工单编号
						type: 'string',
						required: true,
						message: '工单编号不能为空',
						trigger: ['change']
					},
					'PGDBillNO': {
						type: 'string',
						required: true,
						message: '派工单编号不能为空',
						trigger: ['change']
					},
					'ProcedureName': { // 工序
						type: 'string',
						required: true,
						message: '工序不能为空',
						trigger: ['change']
					},
				},
				FilterFormData: { // 主表多选字段数据存储
					MoludData: [],
					MoludDataJoin: '',
				},
				UserWorkshopID: 0,

				BtnApprove: [],
			};
		},
		onLoad(option) {
			let foundNode = null;
			// 获取页面按钮权限
			for (const module of this.$store.state.appConfigInfo.ModuleInfo_All) {
				if (module.TreeTypeName === '生产管理') {
					for (const node of module.Node) {
						if (node.APFunName === '新建停工') {
							foundNode = JSON.parse(JSON.stringify(node));
							break; // 找到后立即退出内层循环  
						}
					}
					if (foundNode) {
						break;
					}
				}
			}
			console.log(foundNode);

			this.BtnApprove = foundNode['IconApprove'];

			if (!this.$utils.isEmpty(option)) {
				this.formData.ProductionStopSingleID = option.id;
				this.isEdit = true;

				// 回显数据
				this.getOrderInfo();
			} else {
				// this.formData.ProductionStopSingleDate = this.$utils.dateFormat(new Date(), 'Y-MM-dd hh:mm:ss');
				this.formData.ProductionStopSingleDate = Number(new Date());
				this.DatetimeData = Number(new Date());
				this.getEmplInfo();
			}

			this.GetUserWorkshop();

		},
		onUnload() {
			uni.$off('ProductionStopDetail_Choice');
			uni.$off('ProductionStopDetail_Scan');
		},
		mounted() {
			let that = this;

			uni.$on('ProductionStopDetail_Choice', function(ret) {
				console.log(ret);
				if (ret.type == '工序') {

					that.formData = Object.assign(that.formData, ret.data);

					that.clearFormData(that.formData, ['EquipmentID', 'EquipmentName',
						'Old_MoludID', 'Old_MoludName', 'StartSingleID', 'KGBillNO'
					])

					setTimeout(() => {
						that.$refs.uForm.validate('ProcedureName');
					}, 300)
				} else if (ret.type == '操作人') {

					that.formData = Object.assign(that.formData, ret.data);

				} else if (ret.type == '设备') {

					that.formData = Object.assign(that.formData, ret.data);

				} else if (ret.type == '派工单编号') {

					that.formData = Object.assign(that.formData, ret.data);

					that.clearFormData(that.formData, ['JobPROCID', 'FlowOrder', 'WoPROCID', 'FWorkshopID',
						'FWorkshopName', 'ProcedureID', 'ProcedureName', 'EquipmentID', 'EquipmentName',
						'Old_MoludID', 'Old_MoludName', 'StartSingleID', 'KGBillNO'
					])

					that.getProcedureInfo();

					setTimeout(() => {
						that.$refs.uForm.validate();
					}, 300)


				}
			})


			setTimeout(() => {
				that.BtnShow = true;
			}, 300);


			// PDA扫码处理
			uni.$on('ProductionStopDetail_Scan', function(content) {
				console.log(content)
				that.getScanInfo(content)
			})
		},
		methods: {
			ApproveBack(str) {
				let that = this;
				console.log(that.BtnApprove);
				let Type = that.BtnApprove.some(item => {
					return item.MenuName == str
				})

				return Type;
			},
			GetUserWorkshop() {
				let that = this;

				let UserID = that.$store.state.UserInfo.UserID;

				let sql = `select isnull(FWorkshopID,0) as FWorkshopID from SYS_User where UserID=${UserID}`;
				//console.log(sql);
				try {
					that.$requestByUrl("/SQLData/QuerySql", {
						sql: sql
					}, function(data) {
						if (data.ds.length && data.ds[0].hasOwnProperty("FWorkshopID")) {
							that.UserWorkshopID = data.ds[0].FWorkshopID;
						}
					});
				} catch (e) {
					console.log(e);
					that.UserWorkshopID = 0;
				}



			},
			getEmplInfo() {
				let that = this;
				that.formData.EmplID = that.$store.state.UserInfo.EmplID || 0;
				that.formData.EmplName = that.$store.state.UserInfo.EmplName || '';
			},
			mainCellBlur(e, type) { // 输入框失焦

			},
			ClosePicker() { // 关闭时间选择器
				// this.formData.ProductionStopSingleDate = Number(new Date());
				this.DatetimeData = +this.formData.ProductionStopSingleDate;
				this.formData.ProductionStopSingleDate = +this.formData.ProductionStopSingleDate;
				this.showTimePicker = false;
			},
			ConfirmTime(data) {
				this.formData.ProductionStopSingleDate = data.value;
				this.showTimePicker = false;
			},
			formatter(type, value) { // 时间选择器数据格式化
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				if (type === 'hour') {
					return `${value}时`
				}
				if (type === 'minute') {
					return `${value}分`
				}
				return value
			},
			sendListRefresh() { // 触发刷新列表数据
				uni.$emit('refresh_ProductionStopList')
			},
			getOrderInfo() { // 获取回显数据
				let that = this;


				this.Request.request('SCTG_Detail', {
					ProductionStopSingleID: this.formData.ProductionStopSingleID,
				}, (ret) => {
					console.log(ret);
					if (ret.status == 200) {
						Object.assign(that.formData, ret.data.ds[0]);

					} else {
						that.$utils.msg('请求异常，请重试！')
					}
				})

			},
			openBaseScreen(str, type) { // 前往筛选页
				let that = this;
				if (type == 'radio') {
					let obj = null;
					let url = '/commonPage/Tool/baseScreen';
					if (str == '工序') {
						if (!this.formData.JobOrderID) {
							return this.$utils.msg('派工单不能为空！！')
						}

						obj = {
							allowClear: false,
							cmd: 'SCTG_GX_Drop',
							type: str,
							ListeningName: 'ProductionStopDetail_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: 'SearchKey', //搜索关键词，应包含在param中
								showText: 'ProcedureName', //查询结果显示的字段
								// pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								subText: [{
									label: '生产车间：',
									labelKey: 'FWorkshopName'
								}],
								ChoiceDataKey: 'ProcedureID',
								ChoiceDataData: this.formData['ProcedureID'],
							},
							param: {
								SearchKey: '',
								JobOrderID: that.formData.JobOrderID,
							}
						}

					} else if (str == '检验员') {

						obj = {
							allowClear: false,
							cmd: 'ST_SCJLRYXL',
							type: str,
							ListeningName: 'ProductionStopDetail_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: true, //是否分页
								searchKey: 'SearchKey', //搜索关键词，应包含在param中
								showText: 'EmplName', //查询结果显示的字段
								pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								ChoiceDataKey: 'EmplID', // 隐藏值
								ChoiceDataData: this.formData.EmplID, //选中的数据
							},
							param: {
								SearchKey: '',
								pageIndex: 1,
								pageSize: 30
							}
						}

					} else if (str == '设备') {
						if (!this.formData.ProcedureID || !this.formData.JobPROCID) {
							return this.$utils.msg('工序不能为空！！')
						}

						obj = {
							allowClear: false,
							cmd: 'SCTG_Equipment_Drop',
							type: str,
							ListeningName: 'ProductionStopDetail_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: true, //是否分页
								searchKey: 'SearchKey', //搜索关键词，应包含在param中
								showText: 'EquipmentName', //查询结果显示的字段
								pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								subText: [{
									label: '机台号：',
									labelKey: 'MachineNumber'
								}, {
									label: '开工单号：',
									labelKey: 'KGBillNO'
								}, {
									label: '模具信息：',
									labelKey: 'Old_MoludName'
								}],
								ChoiceDataKey: 'EquipmentID', // 隐藏值
								ChoiceDataData: this.formData.EquipmentID, //选中的数据
							},
							param: {
								SearchKey: '',
								pageIndex: 1,
								pageSize: 30,
								JobPROCID: this.formData.JobPROCID || 0,
								FWorkshopID: this.formData.FWorkshopID || 0
							}
						}
					} else if (str == '操作人') {

						obj = {
							allowClear: false,
							cmd: 'SCTG_Employee_Drop',
							type: str,
							ListeningName: 'ProductionStopDetail_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: true, //是否分页
								searchKey: 'SearchKey', //搜索关键词，应包含在param中
								showText: 'EmplName', //查询结果显示的字段
								pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								ChoiceDataKey: 'EmplID', // 隐藏值
								ChoiceDataData: this.formData.EmplID, //选中的数据
							},
							param: {
								SearchKey: '',
								pageIndex: 1,
								pageSize: 30,
								FWorkshopID: this.formData.FWorkshopID || 0
							},
						}
					} else if (str == '派工单编号') {

						obj = {
							allowClear: false,
							cmd: 'SCTG_PGD_Drop',
							type: str,
							ListeningName: 'ProductionStopDetail_Choice',
							// multiple: false,
							serverSearch: {
								isPaging: true, //是否分页
								searchKey: 'SearchKey', //搜索关键词，应包含在param中
								showText: 'PGDBillNO', //查询结果显示的字段
								pageIndexStr: 'pageIndex', //分页页码字段，应包含在param中
								subText: [{
									label: '工单单号：',
									labelKey: 'GDBillNO'
								}, {
									label: '产品信息：',
									labelKey: 'ProductName'
								}],
								ChoiceDataKey: 'JobOrderID', // 隐藏值
								ChoiceDataData: this.formData.JobOrderID, //选中的数据
							},
							param: {
								SearchKey: '',
								pageIndex: 1,
								pageSize: 30,

							},
						}
					}

					this.$store.commit('ChangeAndSetStateData', {
						Name1: 'BaseScreenParm',
						data: obj
					})

					uni.navigateTo({
						url: url
					})

				} else if (type == 'picker') {

					if (str == '停工日期') {
						this.DatetimeData = +this.formData.ProductionStopSingleDate;
						this.showTimePicker = true;
					}

				}

			},
			deleteRow() { // 确认删除按钮
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否删除？？',
					success: function(res) {
						if (res.confirm) {
							that.Request.request('SCTG_Delete', {
								ProductionStopSingleID: that.formData.ProductionStopSingleID
							}, function(ret) {
								console.log(ret);
								if (ret.status == 200) {
									if (ret.data.ds[0]['status'] == 200) {
										that.sendListRefresh();
										uni.showToast({
											title: ret.data.ds[0]['msg']
										})
										uni.navigateBack();
									} else {
										that.$utils.layer.alert(ret.data.ds[0]['msg'])
									}
								} else {
									that.$utils.msg('删除失败，请重试')
								}
							})
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				})


			},
			insetRow() {
				let that = this;

				this.$refs.uForm.validate().then(res => {
					that.$utils.showLoading();
					let obj = {
						ProductionStopSingleDate: that.$utils.dateFormat(that.formData
							.ProductionStopSingleDate,
							'Y-MM-dd hh:mm:ss'),

						JobOrderID: that.formData.JobOrderID,
						WoOrderID: that.formData.WoOrderID,
						ProductID: that.formData.ProductID,
						UnitID: that.formData.UnitID,

						ProcedureID: that.formData.ProcedureID,
						FWorkshopID: that.formData.FWorkshopID,
						JobPROCID: that.formData.JobPROCID,
						WoPROCID: that.formData.WoPROCID,

						EmplID: that.formData.EmplID,
						EquipmentID: that.formData.EquipmentID,
						Old_MoludID: that.formData.Old_MoludID,
						StartSingleID: that.formData.StartSingleID,

						Comment: that.formData.Comment,
					};

					that.Request.request('SCTG_Add', obj, (ret) => {
						console.log(ret);
						if (ret.status == 200) {
							that.$utils.hideLoading();

							if (ret.data.ds[0]['status'] == 200) {
								that.formData.ProductionStopSingleID = ret.data.ds[0][
									'ProductionStopSingleID'
								];
								that.isEdit = true;

								// 回显数据
								that.getOrderInfo();

								that.sendListRefresh();
								uni.showToast({
									title: ret.data.ds[0]['msg']
								})

							} else if (ret.data.ds[0]['status'] == 500) {
								that.$utils.layer.alert(ret.data.ds[0]['msg'])
							} else {
								that.$utils.msg('提交失败，请重试！')
							}

						} else {

							that.$utils.hideLoading();
							that.$utils.msg('接口请求失败')
						}
					})

				}).catch(errors => {
					that.$utils.hideLoading();
					console.log(JSON.stringify(errors))
					if (Array.isArray(errors)) {
						// that.showLoading = false;
						uni.$u.toast('请完善表单')
					}
				});

			},
			saveRow() { // 提交
				let that = this;

				this.$refs.uForm.validate().then(res => {
					that.$utils.showLoading();


					let obj = {
						ProductionStopSingleID: that.formData.ProductionStopSingleID, // 停工主键id
						ProductionStopSingleDate: that.$utils.dateFormat(that.formData
							.ProductionStopSingleDate,
							'Y-MM-dd hh:mm:ss'),

						JobOrderID: that.formData.JobOrderID,
						WoOrderID: that.formData.WoOrderID,
						ProductID: that.formData.ProductID,
						UnitID: that.formData.UnitID,

						ProcedureID: that.formData.ProcedureID,
						FWorkshopID: that.formData.FWorkshopID,
						JobPROCID: that.formData.JobPROCID,
						WoPROCID: that.formData.WoPROCID,

						EmplID: that.formData.EmplID,
						EquipmentID: that.formData.EquipmentID,
						Old_MoludID: that.formData.Old_MoludID,
						StartSingleID: that.formData.StartSingleID,

						Comment: that.formData.Comment,
					};

					console.log(obj);

					try {
						that.Request.request('SCTG_Edit', obj, (ret) => {
							console.log(ret);
							if (ret.status == 200) {
								that.$utils.hideLoading();

								if (ret.data.ds[0]['status'] == 200) {
									uni.showToast({
										title: ret.data.ds[0]['msg']
									})
									setTimeout(() => {
										that.sendListRefresh();
									}, 1000)
								} else {
									that.$utils.layer.alert(ret.data.ds[0]['msg'])
								}

							} else {

								that.$utils.hideLoading();
							}
						}, (err) => {
							that.$utils.hideLoading();
							console.log(err);
						})

					} catch (e) {
						that.$utils.hideLoading();
						//TODO handle the exception
					}


				}).catch(errors => {
					that.$utils.hideLoading();
					console.log(JSON.stringify(errors))
					if (Array.isArray(errors)) {
						// that.showLoading = false;
						uni.$u.toast('请完善表单')
					}
				});

			},
			nextRow() { // 继续停工
				let that = this;
				this.pageInit();
			},
			pageInit() { // 页面初始化  
				this.clearFormData(this.formData, ['ProductionStopSingleID', 'ProductionStopSingleDate', 'BillDate',
					'JobOrderID', 'PGDBillNO', 'WoOrderID', 'GDBillNO', 'ProductID', 'ProductName', 'UnitID',
					'UnitName',
					'ProcedureID', 'ProcedureName', 'FWorkshopID', 'FWorkshopName', 'JobPROCID', 'WoPROCID',
					'EmplID', 'EmplName', 'EquipmentID', 'EquipmentName', 'Old_MoludID', 'Old_MoludName',
					'StartSingleID', 'KGBillNO',
					'Comment'
				]);
				this.getEmplInfo();
				this.formData.ProductionStopSingleDate = Number(new Date());
				this.DatetimeData = Number(new Date());
				this.isEdit = false;

			},
			clearFormData(cloneData, excludeArr) {
				// let cloneData = deepClone(data);

				Object.keys(cloneData).forEach(key => {
					if (!!excludeArr.includes(
							key)) {
						// 检查cloneData[key]的类型，并相应地设置值  
						if (cloneData[key] === null) {
							// 如果为null，则保持为null  
							cloneData[key] = null;
						} else if (Array.isArray(cloneData[key])) {
							// 如果为数组，则清空数组  
							cloneData[key] = [];
						} else if (typeof cloneData[key] === 'object' && cloneData[key] !==
							null) {
							// 如果为对象（且不是null），则清空对象  
							cloneData[key] = {};
						} else if (typeof cloneData[key] === 'number') {
							// 如果为number，则设置为0  
							cloneData[key] = 0;
						} else {
							// 其他情况，设置为空字符串  
							cloneData[key] = '';
						}
					}
				});

			},
			OpenScanBtn() { // 扫码按钮
				let that = this;

				this.$scanPopup.openScan({
					scanType: ['qrCode'],
					success: (res) => {
						console.log(res)
						that.getScanInfo(res.result);


					}
				});
			},
			getScanInfo(code) {
				let that = this;
				try {
					let Prefix = code.split('|')[0];
					// if (Prefix == 'EQ' || Prefix == 'SB') {
					// 	that.getScanInfoByEquipment(code);
					// } else 
					if (Prefix == 'PGD') {
						that.getScanInfoByPGD(code);
					} else {
						that.$utils.msg('请扫描正确的二维码')
					}
				} catch (e) {
					console.log(e)
					that.$utils.msg('请扫描正确的二维码')
				}
			},
			getScanInfoByEquipment(scanCode) { // 扫描设备码
				let that = this;
				console.log(scanCode);

				let ID = scanCode.split('|')[1];
				console.log(ID);
				this.Request.request('SCTG_getScanInfoByEquipment', {
					EquipmentID: ID,
				}, (ret) => {
					console.log(ret);
					if (ret.status == 200) {
						if (ret.data.ds[0].status == 500) {
							that.$utils.msg(ret.data.ds[0].msg)
						} else {
							that.formData = Object.assign(that.formData, ret.data.ds[0]);
						}

					} else {
						that.$utils.msg('请求异常，请重试！')
					}
				})

			},
			getScanInfoByPGD(scanCode) { // 扫描派工单二维码
				let that = this;
				console.log(scanCode);

				let ID = scanCode.split('|')[1];
				console.log(ID);
				this.Request.request('SCTG_getScanInfoByPGD', {
					JobOrderID: ID,
				}, (ret) => {
					console.log(ret);
					if (ret.status == 200) {
						if (ret.data.ds[0].status == 500) {
							that.$utils.msg(ret.data.ds[0].msg)
						} else {
							that.formData = Object.assign(that.formData, ret.data.ds[0]);

							that.clearFormData(that.formData, ['JobPROCID', 'FlowOrder', 'WoPROCID', 'FWorkshopID',
								'FWorkshopName', 'ProcedureID', 'ProcedureName', 'EquipmentID',
								'EquipmentName',
								'Old_MoludID', 'Old_MoludName', 'StartSingleID', 'KGBillNO'
							])

							that.getProcedureInfo();

							setTimeout(() => {
								that.$refs.uForm.validate();
							}, 300)
						}

					} else {
						that.$utils.msg('请求异常，请重试！')
					}
				})

			},
			getProcedureInfo() {
				let that = this;

				this.Request.request('SCTG_GX_Drop', {
					JobOrderID: that.formData.JobOrderID,
				}, (ret) => {
					console.log(ret);
					if (ret.status == 200) {
						if (ret.data.ds.length) {

							let ProcessData = {};
							if (that.UserWorkshopID) {
								let filterData = ret.data.ds.filter((item) => {
									return item.FWorkshopID == that.UserWorkshopID;
								})
								if (filterData.length) {
									ProcessData = filterData[0];
								} else {
									ProcessData = ret.data.ds[0];
								}
							} else {
								ProcessData = ret.data.ds[0];
							}

							that.formData = Object.assign(that.formData, ProcessData);
							that.$refs.uForm.validate();
							console.log(that.formData)
						}

					} else {
						that.$utils.msg('请求异常，请重试！')
					}
				})

			},
		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		height: 100vh;
		// height: calc(100vh - 60px);
		background-color: #f9f9f9;

		uni-button {
			margin-left: initial !important;
			margin-right: initial !important;
		}

		.MainPopup {
			flex: initial !important;
		}

		.content_main {
			flex: 1;
			overflow: auto;
			// padding: 10px;

			// 表单1
			.u-form {
				// padding: 0px 10px;
				padding-bottom: 20px;

				.u-form-item {
					background-color: #fff;
					padding: 0 6px 0 12px;

					.u-form-item__body {
						padding: 8px 0 !important;

						.uni-input-placeholder {
							font-size: 12px;
						}
					}

					.TabsBox {
						padding: 0px 15px;
						background-color: #fff;

						.u-tabs__wrapper__nav__item__text {
							padding: 4px 10px !important;
							min-width: 80px;
							text-align: center;
							font-weight: 600;
							border-radius: 15px;
						}
					}


				}

				.PriceItem {

					.u-form-item__body__left__content__label {
						font-size: 12px !important;
					}
				}

				.TopOption {

					.u-form-item__body {
						flex-direction: column !important;
					}
				}

				// 起止时间
				.ChoiceTimesBox {
					width: 100%;
					display: flex;
					align-items: center;
					// background-color: #fff;
					// padding: 18px 10px;
					// margin-top: 10px;

					.TimeBox {
						flex: 1;
						display: flex;
						align-items: center;
						justify-content: space-evenly;

						.timer {
							width: 100%;
							flex: 2;
							display: flex;
							flex-direction: column;
							// align-items: center;
							font-size: 16px;
							color: #333;

							text:first-child {
								margin-bottom: 10px;
								font-weight: 600;
							}

							text:last-child {
								height: 20px;
								font-size: 14px;
							}
						}

						.Icon {
							flex: 1;
						}
					}
				}


				// 上传-删除图标
				.u-upload__deletable {
					width: 20px;
					height: 20px;

					.u-upload__deletable__icon {
						right: -1px !important;

						.u-icon__icon {
							font-size: 20px !important;
							line-height: 16px !important;
						}
					}
				}
			}
		}

		.content_bottom {
			background-color: #fff;

			uni-button {
				font-size: 26rpx !important;
				margin-left: 8rpx !important;
			}
		}

		.BottomBox {
			uni-button {
				margin-right: 10px !important;
			}
		}
	}

	// 复选框样式 start
	.uni-checkbox-input {
		border: 2px solid #d1d1d1 !important;
		border-radius: 9999px !important;
	}

	.uni-checkbox-input-checked {
		background: #51d0d0;
		color: #fff !important;
		border-color: #51d0d0 !important;
	}

	// 复选框样式 End
</style>